#读取文件
# file=open('account_manage/ATM.py','r',encoding='utf8')
# r = file.readlines()
# print(r)
# print("\n",'='*10,'hrjt','='*10)
#清空并重新写入
# file=open('a.txt','w',encoding='utf8')
# print("\n 即将显示....\n")
# file.close()
# file=open('a.txt','r',encoding='utf8')
# r = file.readlines()
# print(r)
# 关闭文件
# with open('a.txt','w') as a:
#     pass
# print('\n即将显示..\n')
#写入
# file=open('a.txt','w',encoding='utf8')
# file.write("你好朋友")
# file.close()
#异常处理
# try:
#     with open('a.txt','r',encoding='utf8') as file:
#         line = file.readlines()
#         print(line)
# except FileNotFoundError:
#     print("文件不存在")
# except PermissionError:
#     print("没有文件访问权限")
#用openpyxl操作excel
import openpyxl
# workbook = openpyxl.Workbook('user.xlsx')
# workbook.create_sheet(title='two sheet')
# workbook.create_sheet(index=0,title='one sheet')
# workbook.save('user.xlsx')
# workbook=openpyxl.load_workbook('user.xlsx')
# workbook.remove(workbook['two sheet'])
# workbook.save('user.xlsx')
#写入单元格数据
# workbook=openpyxl.load_workbook('user.xlsx')
# worksheet = workbook['one sheet']
# worksheet['A1'] = 'name'
# worksheet['B1'] = 'age'
# worksheet['A2'] = '张三'
# worksheet['B2'] = 18
# worksheet.cell(row=3,column=1,value='李四')
# worksheet.cell(row=3,column=2,value=19)
# workbook.save('user.xlsx')
#用list批量写入
# workbook = openpyxl.load_workbook('user.xlsx')
# worksheet=workbook.create_sheet(title='user')
# data=[
# ["姓名","年龄","性别"],
#     ["张三",18,"男"],
#     ["李四",19,"女"],
#     ["王五",20,"男"],
#     ["赵六",21,"男"],
#     ["孙七",22,"女"],
#     ["周八",23,"男"],
#     ["吴九",24,"女"],
#     ["郑十",25,"男"],
#     ["王十一",26,"男"],
#     ["张十二",27,"男"],
#     ["李十三",28,"女"],
#     ["王十四",29,"男"],
#     ["王十五",30,"男"],
#     ["王十六",31,"男"],
#     ["王十七",32,"女"]
# ]
# for i in data:
#     worksheet.append(i)#按行写入
# workbook.save('user.xlsx')
# range写入
# workbook=openpyxl.load_workbook('user.xlsx')
# worksheet=workbook.create_sheet(title='range写入')
# for i in range(1,21):
#     worksheet.append(range(1,21))
# workbook.save('user.xlsx')
#读取单元格
# workbook = openpyxl.load_workbook('user.xlsx')
# worksheet = workbook['user']
# r = worksheet['B2']
# print(r.value)
# r1 = worksheet.cell(row=3,column=2).value
# print(r1)
#获取单元格的全部
# workbook = openpyxl.load_workbook('user.xlsx')
# worksheet = workbook['user']
# print("循环遍历获取")
# for i in worksheet.rows:
#     for j in i:
#         print(j.value,end='\t')
#     print()
#读取整行，整列，或部分几行，部分整列
# workbook = openpyxl.load_workbook('user.xlsx')
# sheet = workbook['user']
# rows = sheet[3]
# columns = sheet['A']
# print(rows)
# for i in columns:
#     print(i.value,end='\t')
#按行读取部分行部分列
# for row in sheet.iter_rows(min_row=1,max_row=3,min_col=1,max_col=3):
#     for cell in row:
#         print(cell.value,end='\t')
#     print()
#按列读取所有内容
# for col in sheet.iter_cols():
#     for cell in col:
#         print(cell.value,end='\t')
#     print()
#按列读取部分列
# for col in sheet.iter_cols(min_row=1,max_row=3,min_col=1,max_col=3):
#     for cell in col:
#         print(cell.value,end='\t')
#     print()
#删除工作表
# workbook=openpyxl.load_workbook('user.xlsx')
# print('删除工作表')
# workbook.remove(workbook['one sheet'])
# workbook.save('user.xlsx')
# print(workbook.sheetnames)




